﻿@model List<SnongPhoneShop.Models.Banner>
@{
    ViewBag.Title = "Quản lý banner";
    Layout = "~/Views/Shared/_LayoutShamcey.cshtml";
}
<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery('#banner-menu').addClass('active');
        // dynamic table
        jQuery('#dyntable').dataTable({
            "sPaginationType": "full_numbers",
            "aaSortingFixed": [[0, 'asc']],
            "fnDrawCallback": function (oSettings) {
                jQuery.uniform.update();
            }
        });

        jQuery('.checkall').click(function(){
            var parentTable = jQuery(this).parents('table');
            var ch = parentTable.find('tbody input[type=checkbox]');
            if(jQuery(this).is(':checked')) {
                    //check all rows in table
                    ch.each(function(){
                            jQuery(this).attr('checked',true);
                            jQuery(this).parent().addClass('checked');	//used for the custom checkbox style
                            jQuery(this).parents('tr').addClass('selected'); // to highlight row as selected
                        });
                } else {
                    //uncheck all rows in table
                    ch.each(function(){
                            jQuery(this).attr('checked',false);
                            jQuery(this).parent().removeClass('checked');	//used for the custom checkbox style
                            jQuery(this).parents('tr').removeClass('selected');
                        });
                }
        });

        jQuery('.deleterow').click(function(){
            var conf = confirm('Bạn muốn xóa vĩnh viễn banner ' + jQuery(this).data('name') + ' (' + jQuery(this).data('val') + ')?');
            if (conf) {
                //jQuery.get('/Admin/DeleteProduct', { id: jQuery(this).data('val') });
                jQuery.ajax({
                    url: '/Admin/DeleteBanner',
                    data: { id: jQuery(this).data('val') },
                    cache: false
                })
                jQuery(this).parents('tr').fadeOut(function () {
                    jQuery(this).remove();
                });
            }
            return false;
        });

        jQuery('.publish').click(function () {
            if (jQuery('.checkitem:checked').length > 0) {
                var list = [];
                jQuery('.checkitem:checked').each(function () {
                    list.push(jQuery(this).val());
                })
                jQuery.ajax({
                    url: '/Admin/SetListPublishStatus',
                    data: { list: list.toString(), status: true },
                    cache: false
                })
            } else {
                return false;
            }
        })

        jQuery('.unpublish').click(function () {
            if (jQuery('.checkitem:checked').length > 0) {
                var list = [];
                jQuery('.checkitem:checked').each(function () {
                    list.push(jQuery(this).val());
                })
                //jQuery.get('/Admin/SetListPublishStatus', { list: list.toString(), status: false });
                jQuery.ajax({
                    url: '/Admin/SetListPublishStatus',
                    data: { list: list.toString(), status: false },
                    cache: false
                })
            } else {
                return false;
            }
        })

        jQuery('.delete-list-product').click(function () {
            if (jQuery('.checkitem:checked').length > 0) {
                var conf = confirm('Bạn muốn xóa vĩnh viễn tất cả các sản phẩm đã chọn?');
                if (conf) {
                    var list = [];
                    jQuery('.checkitem:checked').each(function () {
                        list.push(jQuery(this).val());
                    })
                    //jQuery.get('/Admin/DeleteListProduct', { list: list.toString() });
                    jQuery.ajax({
                        url: '/Admin/DeleteListProduct',
                        data: { list: list.toString() },
                        cache: false
                    })
                }
                else {
                    return false;
                }
            } else {
                return false;
            }
        })
    });
</script>
@section breadcrumbs{
    <ul class="list-nostyle list-inline">
        <li><a class="btn btn-primary btn-rounded" href="">Thêm mới</a></li>
        <li><a class="btn btn-danger btn-rounded delete-list-product" href="@Url.Action("QL_Banner")">Xóa</a></li>
        <li><a class="btn btn-rounded publish" href="@Url.Action("QL_Banner")">Publish</a></li>
        <li><a class="btn btn-rounded unpublish" href="@Url.Action("QL_Banner")">Unpublish</a></li>
    </ul>
}
<h4 class="widgettitle">Danh sách banner</h4>
<table id="dyntable" class="table table-bordered responsive">
    <colgroup>
        <col class="con0" style="text-align: center; width: 4%" />
        <col class="con1" />
        <col class="con0" />
        <col class="con1" />
        <col class="con0" />
        <col class="con1" />
        <col class="con0" />
    </colgroup>
    <thead>
        <tr>
            <th class="head0 nosort"><input type="checkbox" class="checkall" /></th>
            <th class="head0">Tên sản phẩm</th>
            <th class="head1">Ảnh</th>
            <th class="head0">Tiêu đề</th>
            <th class="head1">Số thứ tự</th>
            <th class="head0">Published</th>
            <th class="head1">Delete</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var Item in Model)
        {
            <tr>
                <td class="aligncenter">
                    <span class="center">
                        <input type="checkbox" value="@Item.MaAnh" class="checkitem" />
                    </span>
                </td>
                <td>
                    @try
                    {
                    @Item.SanPham.TenSanPham
                    }
                    catch { }
                </td>
                <td><img src="@Item.Anh" class="img-table-banner" /></td>
                <td>@Item.Alt</td>
                <td>@Item.STT</td>
                <td><a href="@Url.Action("ReversePublishBanner", new { id = Item.MaAnh })">@Item.Publish</a></td>
                <td class="centeralign"><a class="deleterow" href="" data-val="@Item.MaAnh" data-name="@Item.Alt"><span class="icon-trash"></span></a></td>
            </tr>
        }
    </tbody>
</table>
